const { DataTypes } = require('sequelize');
const sequelize = require('../config/mysql')

const { MD5Password } = require('../utils/common')

const Admin = sequelize.define('admin', {
    admin_name: {
      type: DataTypes.STRING,
      allowNull: false
    },
    admin_password: {
        type: DataTypes.STRING,
        allowNull: false,
        set (value) {
          this.setDataValue('admin_password', MD5Password(value));
        }
      },
    admin_role: {
        type: DataTypes.STRING,
        allowNull: false,
        defaultValue: '管理员'
    },
    admin_id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        unique: true,
        allowNull: false,
        autoIncrement: true
      },
  }, {
    freezeTableName: true,
    timestamps: false
  })

  module.exports = Admin